#include "tmylabel.h"

#include <QMouseEvent>
#include <QEvent>
#include <QTextCharFormat>
#include <QTextCursor>
#include <QTextEdit>


TMyLabel::TMyLabel(QWidget *parent): QLabel(parent)
{
    setAttribute(Qt::WA_Hover, true);

}

void TMyLabel::mousePressEvent(QMouseEvent *event)
{
    Q_UNUSED(event);
    emit this->Clicked();
}

void TMyLabel::mouseDoubleClickEvent(QMouseEvent *event)
{
    Q_UNUSED(event);
    emit this->dobleClicked();
}

bool TMyLabel::event(QEvent *event)
{
    if(event->type() == QEvent::HoverEnter)
    {
        QFont font = this->font();
        font.setUnderline(true);
        font.pointSize();
        this->setFont(font);


        QPalette plet = this->palette();
        plet.setColor(QPalette::WindowText, Qt::black);
        setPalette(plet);

//        adjustSize();
    } else if (event->type() == QEvent::HoverLeave){
        QFont font = this->font();
        font.setUnderline(false);
        this->setFont(font);

        QPalette plet = this->palette();
        plet.setColor(QPalette::WindowText, Qt::black);// QColor(74, 157, 223)
        setPalette(plet);

    } else if (event->type() == QEvent::MouseButtonPress){
        QFont font = this->font();
        font.setUnderline(false);
        this->setFont(font);

        QPalette plet = this->palette();
        plet.setColor(QPalette::WindowText, Qt::black);
        setPalette(plet);

    } else if (event->type() == QEvent::MouseButtonRelease){
        QFont font = this->font();
        font.setUnderline(true);
        this->setFont(font);

        QPalette plet = this->palette();
        plet.setColor(QPalette::WindowText, Qt::black);
        setPalette(plet);

    } else if (event->type() == QEvent::MouseButtonDblClick){
        QFont font = this->font();
        font.setUnderline(false);
        this->setFont(font);

        QPalette plet = this->palette();
        plet.setColor(QPalette::WindowText, Qt::black);
        setPalette(plet);

    }

    return QLabel::event(event);
}

